Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
Walkthrough将多任务 CI 工作流简化为单一委托外部工作流的 Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the precision and accuracy of number handling, particularly for very small or very large numbers expressed in scientific notation. It introduces a robust mechanism to expand scientific notation into full decimal strings, which is then integrated into the core number-to-string conversion logic. This ensures that numbers with extreme precision are correctly represented, preventing data loss or incorrect formatting in various scenarios. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Ignored Files
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
|
😭 Deploy PR Preview c572be5 failed. Build logs 🤖 By surge-preview |
There was a problem hiding this comment.
Code Review
This pull request introduces handling for very small numbers in scientific notation, primarily through a new expandScientificNotation function. While reviewing, I identified a critical bug in this new function that leads to incorrect expansion for numbers with a mantissa less than 1. I've provided a detailed comment with a suggested fix to address this issue. The other changes in the pull request appear to correctly integrate this new functionality.
src/numberUtil.ts
Outdated
| const digits = `${integer}${decimal}`.replace(/^0+/, '') || '0'; | ||
| const decimalIndex = integer.length + exp; |
There was a problem hiding this comment.
The calculation for decimalIndex is incorrect for numbers where the mantissa is less than 1 (e.g., 0.123e-5). Using integer.length doesn't work correctly because for numbers like 0.123, integer is 0 and its length is 1, which doesn't capture the true position of the significant digits. This results in an incorrect expansion. For instance, 0.123e-1 is incorrectly expanded to 0.123 instead of the correct 0.0123.
To fix this, the logic for decimalIndex needs to differentiate between numbers with an integer part greater than zero and those that are purely fractional.
| const digits = `${integer}${decimal}`.replace(/^0+/, '') || '0'; | |
| const decimalIndex = integer.length + exp; | |
| const digits = `${integer}${decimal}`.replace(/^0+/, '') || '0'; | |
| if (digits === '0') { | |
| return '0'; | |
| } | |
| let decimalIndex; | |
| if (integer !== '0' || !unsignedMantissa.includes('.')) { | |
| decimalIndex = integer.length + exp; | |
| } else { | |
| const leadingZeros = (decimal.match(/^0*/) || [''])[0].length; | |
| decimalIndex = exp - leadingZeros; | |
| } |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/util.test.tsx (1)
66-70: 建议补充阈值边界断言,锁定> 100分支行为。当前已覆盖
1e-307,建议再补1e-100/1e-101(以及可选负号场景)以防后续修改影响阈值判定。🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/util.test.tsx` around lines 66 - 70, 在现有 getDecimal 测试里补充阈值边界用例以锁定 “> 100” 分支:添加对 '1e-100' 和 '1e-101'(以及可选的负数 '-1e-100' 和 '-1e-101')的断言,使用与现有用例相同的比较风格(参照 tinyScientificValue 和 mockSupportBigInt 的现有断言)以确保当指数跨越 100 时行为不变;定位 getDecimal、tinyScientificValue、mockSupportBigInt 并在 tests/util.test.tsx 中新增这些断言以覆盖边界并防止阈值回归。
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/util.test.tsx`:
- Around line 66-70: 在现有 getDecimal 测试里补充阈值边界用例以锁定 “> 100” 分支:添加对 '1e-100' 和
'1e-101'(以及可选的负数 '-1e-100' 和 '-1e-101')的断言,使用与现有用例相同的比较风格(参照 tinyScientificValue
和 mockSupportBigInt 的现有断言)以确保当指数跨越 100 时行为不变;定位
getDecimal、tinyScientificValue、mockSupportBigInt 并在 tests/util.test.tsx
中新增这些断言以覆盖边界并防止阈值回归。
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4fb4522e-647c-4127-b5e3-6c6ce62327c2
📒 Files selected for processing (4)
.github/workflows/main.ymlsrc/NumberDecimal.tssrc/numberUtil.tstests/util.test.tsx
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/main.yml:
- Around line 7-8: 不要将可复用工作流引用固定为 `@main` 并同时使用 secrets: inherit;把 uses:
react-component/rc-test/.github/workflows/test.yml@main 改为指向上游仓库的不可变 commit SHA
(例如 ...@<commit-sha>),并删除 secrets: inherit,然后通过上游工作流的 workflow_call 输入或显式
environment/with 参数传递仅需的单个 secrets(或在调用处从 repository secrets 显式注入),确保在调用处列出具体
secret 名称而不是继承全部,以减少供应链与权限风险。
- Line 3: 恢复 workflow 的分支过滤:不要使用无条件的 "on: [push, pull_request]",而是将触发器改回分别声明
push 和 pull_request 并限制 branches 为 master(使用 keys: on -> push -> branches:
[master] 和 on -> pull_request -> branches: [master]),以恢复原有 CI 触发范围。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e1890020-49be-4c93-80d7-bead4ce4e000
📒 Files selected for processing (1)
.github/workflows/main.yml
| branches: [master] | ||
| pull_request: | ||
| branches: [master] | ||
| on: [push, pull_request] |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 验证上一版 `.github/workflows/main.yml` 是否在 `on:` 下保留了分支过滤条件。
# 预期:如果旧文件里在 `push` / `pull_request` 下存在 `branches:`,
# 说明这次改动放宽了触发范围,需要把过滤条件补回。
prev="$(git log --format=%H -- .github/workflows/main.yml | sed -n '2p')"
if [ -z "$prev" ]; then
echo "本地历史里没有找到 .github/workflows/main.yml 的上一版。" >&2
exit 1
fi
echo "=== 上一版 workflow 头部 ($prev) ==="
git show "${prev}:.github/workflows/main.yml" | sed -n '1,40p'
echo
echo "=== 当前 workflow 头部 ==="
sed -n '1,40p' .github/workflows/main.ymlRepository: react-component/mini-decimal
Length of output: 1817
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 检查当前工作区是否存在 .github/workflows/main.yml
if [ -f ".github/workflows/main.yml" ]; then
echo "=== 当前 workflow on: 配置 (前 20 行) ==="
head -20 .github/workflows/main.yml
echo
fi
# 尝试查看 git 历史(如果存在)
if git rev-parse --git-dir > /dev/null 2>&1; then
echo "=== Git 历史查询 ==="
# 获取涉及该文件的最近 3 个提交
git log --oneline -n 3 -- .github/workflows/main.yml 2>/dev/null || echo "无法访问 git 历史"
echo
# 尝试获取前一个版本
prev_commit=$(git log --format=%H -- .github/workflows/main.yml 2>/dev/null | sed -n '2p')
if [ -n "$prev_commit" ]; then
echo "=== 前一版本 workflow on: 配置 ($prev_commit) ==="
git show "${prev_commit}:.github/workflows/main.yml" 2>/dev/null | head -20 || echo "无法显示前一版本"
fi
else
echo "当前目录不是 git 仓库"
fiRepository: react-component/mini-decimal
Length of output: 308
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== 查看 .github/workflows/main.yml 的完整 git 历史 ==="
git log --all --oneline -- .github/workflows/main.yml | head -10
echo
echo "=== 显示当前版本的完整内容 ==="
cat .github/workflows/main.yml
echo
echo "=== 尝试显示前一个版本 ==="
# 获取所有涉及该文件的提交
commits=$(git log --format=%H --all -- .github/workflows/main.yml)
commit_array=($commits)
if [ ${`#commit_array`[@]} -gt 1 ]; then
echo "前一版本提交: ${commit_array[1]}"
git show "${commit_array[1]}:.github/workflows/main.yml" 2>/dev/null || echo "无法显示"
else
echo "只有一个提交,无法比较"
# 尝试显示该提交中的变更
if [ ${`#commit_array`[@]} -gt 0 ]; then
echo "显示当前提交 ${commit_array[0]} 中对该文件的改动:"
git show "${commit_array[0]}":".github/workflows/main.yml" 2>/dev/null || echo "无法显示"
fi
fiRepository: react-component/mini-decimal
Length of output: 3224
🏁 Script executed:
#!/bin/bash
# 显示应该的修复方案
echo "=== 应该恢复的配置 ==="
cat <<'EOF'
on:
push:
branches: [master]
pull_request:
branches: [master]
EOFRepository: react-component/mini-decimal
Length of output: 161
需要恢复 workflow 的分支过滤条件。
Line 3 将触发器改成了无条件的 on: [push, pull_request],而原配置在 push 和 pull_request 上都限制了 branches: [master]。这扩大了 CI 触发范围,与 PR 目标中的"保持现有行为"不符。请将分支过滤条件恢复:
on:
push:
branches: [master]
pull_request:
branches: [master]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.github/workflows/main.yml at line 3, 恢复 workflow 的分支过滤:不要使用无条件的 "on: [push,
pull_request]",而是将触发器改回分别声明 push 和 pull_request 并限制 branches 为 master(使用 keys:
on -> push -> branches: [master] 和 on -> pull_request -> branches:
[master]),以恢复原有 CI 触发范围。
| uses: react-component/rc-test/.github/workflows/test.yml@main | ||
| secrets: inherit |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
git ls-files | grep -E "\.github/workflows"Repository: react-component/mini-decimal
Length of output: 128
🏁 Script executed:
cat -n .github/workflows/main.ymlRepository: react-component/mini-decimal
Length of output: 268
不要把继承 secrets 的复用工作流绑定到 @main。
Line 7 引用的是外部仓库的 reusable workflow,Line 8 又继承了全部 secrets。@main 是可变引用,上游后续提交会直接改变这里执行的 CI 内容;和 secrets: inherit 组合后,供应链与最小权限风险都会被放大。建议固定到 commit SHA,并改成按 workflow_call 显式传递所需 secrets。
建议修改
- uses: react-component/rc-test/.github/workflows/test.yml@main
+ uses: react-component/rc-test/.github/workflows/test.yml@<pinned-commit-sha>🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.github/workflows/main.yml around lines 7 - 8, 不要将可复用工作流引用固定为 `@main` 并同时使用
secrets: inherit;把 uses: react-component/rc-test/.github/workflows/test.yml@main
改为指向上游仓库的不可变 commit SHA (例如 ...@<commit-sha>),并删除 secrets: inherit,然后通过上游工作流的
workflow_call 输入或显式 environment/with 参数传递仅需的单个 secrets(或在调用处从 repository secrets
显式注入),确保在调用处列出具体 secret 名称而不是继承全部,以减少供应链与权限风险。
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4 +/- ##
==========================================
- Coverage 91.86% 91.17% -0.69%
==========================================
Files 5 5
Lines 209 238 +29
Branches 56 70 +14
==========================================
+ Hits 192 217 +25
- Misses 17 21 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
tsconfig.json (1)
17-22: tests 目录的 include 模式可能遗漏了.ts文件当前
include配置中,tests目录只包含了*.tsx文件,但测试文件也可能是纯.ts文件。建议添加./tests/**/*.ts模式以确保完整覆盖。♻️ 建议的修改
"include": [ "./src/**/*.ts", "./src/**/*.tsx", "./docs/**/*.tsx", - "./tests/**/*.tsx" + "./tests/**/*.tsx", + "./tests/**/*.ts" ]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tsconfig.json` around lines 17 - 22, tsconfig.json’s "include" array currently only matches "./tests/**/*.tsx", which misses plain .ts test files; update the include array (the "include" entry in tsconfig.json) to also include "./tests/**/*.ts" so all test files under the tests directory are covered.package.json (1)
64-66: 建议更新 Node.js 最低版本要求当前配置的
"node": ">=8.x"与现代依赖不匹配。TypeScript 5.x 需要 Node.js 14.17+,@testing-library/react16.x 需要更高版本。建议将最低版本更新为 Node.js 18.x 以确保兼容性。♻️ 建议的修改
"engines": { - "node": ">=8.x" + "node": ">=18.x" }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@package.json` around lines 64 - 66, The package.json "engines" field currently pins "node": ">=8.x", which is incompatible with modern deps; update the "engines" -> "node" entry to a current minimum (e.g., ">=18.x" or ">=18") to match TypeScript 5.x and modern testing libs, and ensure CI/workflow configs and any engine checks (e.g., in Dockerfiles or .nvmrc) are updated consistently to Node 18 to avoid runtime/installation issues.tests/util.test.tsx (1)
147-159: 建议补充更多边界测试用例当前测试覆盖了负指数的情况,建议考虑添加以下边界用例以增强覆盖:
♻️ 建议添加的测试用例
describe('scientific notation', () => { it('expands fractional mantissas correctly', () => { expect(expandScientificNotation('0.123e-1')).toEqual('0.0123'); expect(expandScientificNotation('-0.123e-1')).toEqual('-0.0123'); expect(expandScientificNotation('0.00123e2')).toEqual('0.123'); expect(expandScientificNotation('0e5')).toEqual('0'); + // 大正指数 + expect(expandScientificNotation('1.5e3')).toEqual('1500'); + expect(expandScientificNotation('1.23e2')).toEqual('123'); }); it('keeps num2str behavior correct for normalized numbers', () => { expect(num2str(1.23e-19)).toEqual(`0.${'0'.repeat(18)}123`); expect(num2str(-1.23e-20)).toEqual(`-0.${'0'.repeat(19)}123`); + // 正指数 + expect(num2str(1.5e10)).toEqual('15000000000'); }); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/util.test.tsx` around lines 147 - 159, Add additional boundary tests for expandScientificNotation and num2str to improve coverage: include exponent zero (e.g., "1.23e0"), positive exponents that increase integer part (e.g., "1.23e3" and "0.00123e5"), very large positive and negative exponents, pure integer mantissas (e.g., "123e-2"), and tiny values that should produce "0" (e.g., "0e0" and extremely negative exponents) to ensure expandScientificNotation and num2str handle zero, positive exponents, integer mantissas, and extreme magnitudes correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@package.json`:
- Around line 28-38: The package.json scripts deploy, now-build and
prepublishOnly reference a non-existent global binary "ut"; update those scripts
to either (A) install the correct devDependency that provides the "ut" binary
(add the package that actually exposes "ut" to devDependencies) and run npm
install, or (B) replace the "ut" invocations with the intended existing npm
script/command (for example use "npm run <script>" or the existing
"rc-test"/"dumi"/build commands) so the scripts succeed; specifically change the
"deploy", "now-build" and "prepublishOnly" script entries to use the correct
tool or add the missing devDependency that exports "ut".
In `@src/numberUtil.ts`:
- Around line 135-140: In NumberDecimal.add() and NumberDecimal.multi(), the
calls to number.toFixed(maxPrecision) must guard against precision > 100
(toFixed supports only 0–100); use getNumberPrecision(numStr) and if precision >
100 call expandScientificNotation(numStr) (same logic as in toString()) instead
of toFixed, otherwise call number.toFixed(precision); update both add() and
multi() to apply this check so they mirror the protection already present in
toString().
---
Nitpick comments:
In `@package.json`:
- Around line 64-66: The package.json "engines" field currently pins "node":
">=8.x", which is incompatible with modern deps; update the "engines" -> "node"
entry to a current minimum (e.g., ">=18.x" or ">=18") to match TypeScript 5.x
and modern testing libs, and ensure CI/workflow configs and any engine checks
(e.g., in Dockerfiles or .nvmrc) are updated consistently to Node 18 to avoid
runtime/installation issues.
In `@tests/util.test.tsx`:
- Around line 147-159: Add additional boundary tests for
expandScientificNotation and num2str to improve coverage: include exponent zero
(e.g., "1.23e0"), positive exponents that increase integer part (e.g., "1.23e3"
and "0.00123e5"), very large positive and negative exponents, pure integer
mantissas (e.g., "123e-2"), and tiny values that should produce "0" (e.g., "0e0"
and extremely negative exponents) to ensure expandScientificNotation and num2str
handle zero, positive exponents, integer mantissas, and extreme magnitudes
correctly.
In `@tsconfig.json`:
- Around line 17-22: tsconfig.json’s "include" array currently only matches
"./tests/**/*.tsx", which misses plain .ts test files; update the include array
(the "include" entry in tsconfig.json) to also include "./tests/**/*.ts" so all
test files under the tests directory are covered.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0e0f1f77-1b04-4456-9689-26a209cc7c66
📒 Files selected for processing (5)
.umirc.tspackage.jsonsrc/numberUtil.tstests/util.test.tsxtsconfig.json

Summary
Testing
Summary by CodeRabbit
发布说明
新功能
测试
杂务